<template>
	<view class="diyTask">
		<diyNavBar value='任务列表' :bottom='20' :fixed = "true"></diyNavBar>
		 <mescroll-body ref="mescrollRef" @down="downCallback" @up="upCallback" :top = '120 + $store.state.statusBarHeight'
		  :up = "upOption" :down="downOption">
			<diyTask :taskSwitch = 'false' :taskList="taskList"></diyTask>
		 </mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import diyNavBar from '../../component/diy-nav/diy-navbar.vue'
	import diyTask from '../../component/diy-task/diy-task.vue'
	export default{
		mixins: [MescrollMixin], // 使用mixin
		components:{
			diyTask,diyNavBar
		},
		data(){
			return {
				name:'',//列表搜索用参数
				taskList:[],//展示的数据
				upOption:{
					page:{
						num:0,
						size:10
					}
				},//上拉参数配置
				downOption:{
					page:{
						num:0,
						size:10
					}
				},//下拉参数配置
				task_sort_id:''//请求的参数
			}
		},
		onLoad(option){
			this.name = option.name?option.name:'';
			this.task_sort_id = option.id?option.id:'';
		},
		methods:{
			// 下拉刷新
			downCallback(page){
				this.mescroll.resetUpScroll()
			},
			//上拉加载
			upCallback(page){
				this.$http.sendrequest('/task/TaskList',{
					page:page.num,
					page_size:page.size,
					name:this.name,
					task_sort_id:this.task_sort_id
				}).then(res=>{
					if(res.code == 1){
						if(page.num == 1) this.taskList = []; //如果是第一页需手动制空列表
						this.taskList = this.taskList.concat(res.data.list);
						this.mescroll.endBySize(res.data.list.length, res.data.count);
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.diyTask{
		background: #f7f7f7;
	}
</style>
